<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../../assets/boostrap/bootstrap.css">
    <style>
        .app {
            width: 500px;
            margin: 0 auto;
        }
        .list-group-item{
            display: flex;
            flex-flow: row nowrap;
            justify-content: space-between;
        }
        .list-group-item .text{
            flex-grow: 1;
            padding: 4px 10px;
        }
        .list-group-item .badge{
            line-height:2;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div id="app" class="app">
        <div class="card text-bg-light mt-3">
            <div class="card-body">
                <p>添加邮箱</p>
                <form class="row g-3 needs-validation" novalidate>
                    <div class="col-12">
                        <input type="text" class="form-control" placeholder="请输入邮箱"
                            :class="{
                                'is-valid':inputEmail!='' && emailReg.test(inputEmail),
                                'is-invalid':inputEmail!='' && !emailReg.test(inputEmail)
                            }"
                            v-model="inputEmail"
                        >
                        <!-- <div class="valid-feedback">
                            Looks good!
                        </div>
                        <div class="invalid-feedback">
                            Looks bad!
                        </div> -->
                    </div>
                    <div class="col-12 d-grid gap-2">
                        <button class="btn btn-success" type="button" 
                            :disabled=" !emailReg.test(inputEmail) "
                            @click="addItem()"
                        >添加邮箱</button>
                    </div>
                </form>
            </div>
        </div>
        <div class="card text-bg-light mt-3">
            <div class="card-body">
                <ul class="list-group">
                    <li class="list-group-item"
                        v-show="emails.length==0"
                    >
                        <span class="text" style="text-align: center;">请先添加邮箱</span>
                    </li>
                    <li class="list-group-item" 
                        v-for="(email,i) in emails"
                    >
                        <input type="checkbox">
                        <span class="text">{{ email }}</span>
                        <span class="badge text-bg-primary">删除</span>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <script src="../../assets/mockjs/mock-min.js"></script>
    <script type="module">
        import { createApp } from "../../assets/vue3/vue.esm-browser.js";
        createApp({
            data() {
                return {
                    emailReg:/^[A-Za-z0-9]{5,10}@[A-Za-z0-9]{3,10}\.(cn|com|net)$/,
                    inputEmail:"",
                    emails:Mock.mock({
                        "list|0":[
                            /^[A-Za-z0-9]{5,10}@[a-z]{5}\.(cn|com|net)$/
                        ]
                    }).list
                }
            },
            methods:{
                addItem(){
                    this.emails.push(this.inputEmail)
                    this.inputEmail = "";
                }
            }
        }).mount("#app");
    </script>
</body>

</html>